Ext.define('HIT.view.MdataClientPanel', {
    extend: 'Ext.form.Panel',
    alias: 'widget.mdataclientpanel',

    cls: 'custom-grid',
    frame: false,
    width: 1200,
	layout: {	
		type: 'anchor'
	},
	title: Share.T('客户主数据'),
	initComponent: function() {
		var me = this;
		Ext.applyIf(me, {
			items: [
				{
					xtype: 'gridpanel',
					id:'mdata-client-main-panel',
					anchor : '100% 50%',
					columnLines: false,
					autoScroll: true,
					store : 'MdataClient',
					title: Share.T('客户基本信息'),
					columns: [
						{
							xtype: 'rownumberer',
							resizable: true,
							width: 30
						},
						{		
							xtype: 'gridcolumn',
							width: 160,
							align: 'center',
							dataIndex : 'code',
							text: Share.T('客户代码')
						},
						{
							xtype: 'gridcolumn',
							width: 200,
							align: 'left',
							style:'text-align:center;',
							dataIndex : 'client_supplier',
							text: Share.T('客户名称')
						},
						{
							xtype: 'gridcolumn',
							align: 'left',
							width: 120,
							style:'text-align:center;',
							dataIndex: 'tax_code',
							text: Share.T('客户纳税人识别号')
						},
						//新增字段，在发票类型表里
						{
							xtype: 'gridcolumn',
							align: 'center',
							width: 120,
							dataIndex: 'invType',
							text: Share.T('发票类型')
						},
						{
							xtype: 'gridcolumn',
							align: 'left',
							width: 120,
							dataIndex: 'bank',
							style:'text-align:center;',
							text: Share.T('客户开户行')
						},
						{
							xtype: 'gridcolumn',
							align: 'left',
							style:'text-align:center;',
							width: 120,
							dataIndex: 'bank_account',
							text: Share.T('客户账号')
						},
						{
							xtype: 'gridcolumn',
							align: 'left',
							width: 120,
							style:'text-align:center;',
							dataIndex: 'address',
							text: Share.T('地址')
						},
						{
							xtype: 'gridcolumn',
							align: 'left',
							width: 120,
							style:'text-align:center;',
							dataIndex: 'tel',
							text: Share.T('客户电话')
						},
						{
							xtype: 'gridcolumn',
							align: 'left',
							width: 120,
							dataIndex: 'ck01',
							style:'text-align:center;',
							text: Share.T('参考字段１')
						},
						{
							xtype: 'gridcolumn',
							align: 'left',
							width: 120,
							dataIndex: 'ck02',
							style:'text-align:center;',
							text: Share.T('参考字段２')
						},
						{
							xtype: 'gridcolumn',
							align: 'left',
							width: 120,
							dataIndex: 'ck03',
							style:'text-align:center;',
							text: Share.T('参考字段３')
						},
						{
							xtype: 'gridcolumn',
							align: 'left',
							width: 120,
							dataIndex: 'ck04',
							style:'text-align:center;',
							text: Share.T('参考字段４')
						},
						{
							xtype: 'gridcolumn',
							align: 'left',
							width: 120,
							dataIndex: 'ck05',
							style:'text-align:center;',
							text: Share.T('参考字段５')
						},
						{
							xtype: 'gridcolumn',
							align: 'center',
							width: 120,
							dataIndex: 'ck06',
							text: Share.T('参考字段６')
						},
						{
							xtype: 'gridcolumn',
							align: 'center',
							width: 120,
							dataIndex: 'ck07',
							text: Share.T('参考字段７')
						},
						{
							xtype: 'gridcolumn',
							align: 'center',
							width: 120,
							dataIndex: 'ck08',
							text: Share.T('参考字段８')
						},
						{
							xtype: 'gridcolumn',
							align: 'center',
							width: 120,
							dataIndex: 'ck09',
							text: Share.T('参考字段９')
						},
						{
							xtype: 'gridcolumn',
							align: 'center',
							width: 120,
							dataIndex: 'ck10',
							text: Share.T('参考字段１０')
						}
					],
					viewConfig: {
						enableTextSelection:true
					},
					selModel: Ext.create('Ext.selection.CheckboxModel', {
					checkOnly: false
					}),
					dockedItems: [
					{
						xtype: 'pagingtoolbar',
						dock: 'bottom',
//						dock: 'bottom',
						id:'mdata-client-pag',
						width: 360,
						inputItemWidth:45,
						displayInfo: true,
						store : 'MdataClient',
						plugins: [{
							ptype: "pagesize",
							uxPageSize: page_size}]
					},{
				    	xtype: 'toolbar',
						dock: 'top',
						items: [
						    {
						    	xtype: 'tbspacer',
						          width: 20
						    },
						    {
						    	xtype: 'textfield',
						    	labelwidth:40,
								width:234,
						    	id: 'mdata-client-info-search',
						    	fieldLabel: Share.T('信息查询'),
						    	name: 'client-info-search',
						    	listeners:{
						    		specialkey : function(field, e) {  
					                     if (e.getKey() == Ext.EventObject.ENTER) {  
//					                        alert("回车事件");  
					                    	Ext.getCmp('mdata-client-info-btn').fireEvent("click");
					                     }  
					                 }  
						    	}
						    },
						    {
						    	xtype: 'tbspacer',
						          width: 20
						    },
						    {
						    	xtype: 'button',
						    	id:'mdata-client-info-btn',
						    	text: Share.T('查询'),
						    	listeners: {
						    			click: {
						    				fn: me.onMdataClientInfoSearch,
						                    scope: me
						    			}
						    	}
						    }
						]   	 
				    } ],
					listeners: {
						itemclick: {
		                    fn: me.onGridpanelSelectionChange,
		                    scope: me
		                },
		                afterrender : function(e) {
		                	var store = Ext.getCmp('mdata-client-main-panel').getStore();
		                	store.currentPage = 1;
		              		store.removeAll();
		              		store.on('beforeload', function(store) {
		              			Ext.apply(store.proxy.extraParams , {});
		              		});
		              		store.load();           
		                }
		            }
				},
				{
					xtype: 'gridpanel',
					id:'mdata-client-detail-panel',
					anchor : '100% 50%',
					columnLines: false,
					autoScroll: true,
					dock: 'top',
					store : 'MdataClientAddress',
					title: Share.T('客户联系方式'),
					columns: [
						{
							xtype: 'rownumberer',
							resizable: true,
							width: 30
						},
						{		
							xtype: 'gridcolumn',
							width: 160,
							align: 'left',
							style:'text-align:center;',
							dataIndex : 'recv_company',
							text: Share.T('收件公司名称')
						},
						{
							xtype: 'gridcolumn',
							width: 200,
							align: 'left',
							style:'text-align:center;',
							dataIndex : 'recv_ticket',
							text: Share.T('发票收件人')
						},
/**
 * 客户联系方式中加入两个字段：收件人邮箱、联系人手机
 * dateIndex:recv_email、recv_phone
 */						{
							xtype: 'gridcolumn',
							align: 'left',
							style:'text-align:center;',
							width: 200,
							dataIndex: 'recv_email',
							text: Share.T('收件人邮箱')
						},
						{
							xtype: 'gridcolumn',
							width: 200,
							align: 'center',
							dataIndex : 'recv_phone',
							text: Share.T('联系人手机')
						},
						{
							xtype: 'gridcolumn',
							align: 'left',
							style:'text-align:center;',
							width: 120,
							dataIndex: 'recv_address',
							text: Share.T('收件人地址')
						},
						{
							xtype: 'gridcolumn',
							align: 'left',
							style:'text-align:center;',
							width: 120,
							dataIndex: 'recv_tel',
							text: Share.T('收件单位电话')
						},
						{
							xtype: 'gridcolumn',
							align: 'left',
							style:'text-align:center;',
							width: 120,
							dataIndex: 'city',
							text: Share.T('城市')
						},
						{
							xtype: 'gridcolumn',
							align: 'left',
							style:'text-align:center;',
							width: 120,
							dataIndex: 'remark',
							text: Share.T('备注')
						},
						{
							xtype: 'gridcolumn',
							align: 'left',
							style:'text-align:center;',
							width: 120,
							dataIndex: 'ck01',
							text: Share.T('参考字段１')
						},
						{
							xtype: 'gridcolumn',
							align: 'left',
							style:'text-align:center;',
							width: 120,
							dataIndex: 'ck02',
							text: Share.T('参考字段２')
						},
						{
							xtype: 'gridcolumn',
							align: 'left',
							style:'text-align:center;',
							width: 120,
							dataIndex: 'ck03',
							text: Share.T('参考字段３')
						},
						{
							xtype: 'gridcolumn',
							align: 'left',
							style:'text-align:center;',
							width: 120,
							dataIndex: 'ck04',
							text: Share.T('参考字段４')
						},
						{
							xtype: 'gridcolumn',
							align: 'left',
							style:'text-align:center;',
							width: 120,
							dataIndex: 'ck05',
							text: Share.T('参考字段５')
						}
					],
					viewConfig: {
						enableTextSelection:true
					},
					selModel: Ext.create('Ext.selection.CheckboxModel', {
						checkOnly: false
					}),
					dockedItems: [
					{
						xtype: 'pagingtoolbar',
//						xtype: 'lzq_pag',
						dock: 'bottom',
						id:'mdata-client-address-pag',
						width: 360,
						inputItemWidth:45,
						displayInfo: true,
						store : 'MdataClientAddress',
						plugins: [{
							ptype: "pagesize",
							uxPageSize: page_size}]
					}]
				}
			]
		});
		me.callParent(arguments);
	},
    onGridpanelSelectionChange: function(record, item, index) {
    	var mainId = item.get('id');
		var AddressStore = Ext.getCmp('mdata-client-detail-panel').getStore();
		AddressStore.removeAll();
		AddressStore.load({
		    params: {mainId:mainId},
		    callback: function(records, options, success){},
		    scope: AddressStore,
		    add: true
		});
    },
    onMdataClientInfoSearch: function(btn,event,eOpts){
    	var searchInfo = Ext.getCmp('mdata-client-info-search').getValue();
    	var ClientStore = Ext.getCmp('mdata-client-main-panel').getStore();
		ClientStore.currentPage = 1;
		ClientStore.removeAll();
		ClientStore.on('beforeload', function(store) {
   			Ext.apply(store.proxy.extraParams , {
   				searchInfo:searchInfo
   			});
        });
		ClientStore.load();
    }
});